package code.starivan.niuke.common;

/**
 * Created by Ivan on 2015/9/9.
 */
public class RotateMatrix {
    public int[][] rotateMatrix(int[][] mat, int n) {
        // write code here
        int rs=0,cols=0,re=n-1,cole=n-1;
        while (rs<re){
            rotateEdge(mat,rs++,cols++,re--,cole--);
        }

        return mat;
    }

    private void rotateEdge(int[][] mat,int rs,int cols,int re,int cole){
        int time=re-rs;
        for(int i=0;i<time;i++){
            int tmp=mat[re-i][cols];
            mat[re-i][cols]=mat[re][cole-i];
            mat[re][cole-i]=mat[rs+i][cole];
            mat[rs+i][cole]=mat[rs][cols+i];
            mat[rs][cols+i]=tmp;
        }
    }
}
